package com.youaishujuhui.devops.web.service;

import java.io.File;
import java.util.Scanner;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

@Service
public class JsonService {
	@Value(value="classpath:config/infocenter.json")
    private Resource infoCenterJsonData;
	
	public String getInfoCenterJsonData(){
        try {
            File file = infoCenterJsonData.getFile();
            String jsonData = this.jsonRead(file);
            
            return jsonData;
        } catch (Exception e) {
            return null;
        }
    }
	
	private String jsonRead(File file){
        Scanner scanner = null;
        StringBuilder buffer = new StringBuilder();
        try {
            scanner = new Scanner(file, "utf-8");
            while (scanner.hasNextLine()) {
                buffer.append(scanner.nextLine());
            }
        } catch (Exception e) {
            
        } finally {
            if (scanner != null) {
                scanner.close();
            }
        }
        return buffer.toString();
    }
}
